import Vue from 'vue'
import store from '@/store'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Layout from '@/views/Layout'
import Home from '@/views/Home'
// import User from '@/views/User'
// import Search from '@/views/Search'
// import SearchResults from '@/views/Search/SearchResults'
// import ArticleDetail from '@/views/ArticleDetail'
// import UserEdit from '@/views/User/UserEdit.vue'
// import Chat from '@/views/Chat'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/layout'
  },
  {
    path: '/login',
    component: Login,
    beforeEnter: (to, from, next) => {
      if (store.state.token.length) {
        next(false) // 原地留下
      } else { // 其他情况统统放行
        next()
      }
    }
  },
  {
    path: '/layout',
    component: Layout,
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        component: Home,
        meta: {
          istrue: true,
          istop: 0
        }
      }, {
        path: 'user',
        // component: User
        component: () => import(/* webpackChunkname:"User" */ '@/views/User')
      }
    ]
  }, {
    path: '/search',
    // component: Search
    component: () => import(/* webpackChunkname:"Search" */ '@/views/Search')
  }, {
    //  动态路由
    path: '/search/:keywords',
    // component: SearchResults
    component: () => import(/* webpackChunkname:"SearchResults" */ '@/views/Search/SearchResults')
  },
  {
    // 查询字符串的方式
    path: '/article',
    // component: ArticleDetail
    component: () => import(/* webpackChunkname:"ArticleDetail" */ '@/views/ArticleDetail')
  }, {
    path: '/user/edit',
    // component: UserEdit
    component: () => import(/* webpackChunkname:"UserEdit" */ '@/views/User/UserEdit.vue')
  }, {
    path: '/chat',
    // component: Chat
    component: () => import(/* webpackChunkname:"Chat" */ '@/views/Chat')
  }]
const router = new VueRouter({ routes })

export default router
